import { Auth } from '@/decorator/auth.decorator';
import { PrismaService } from '@/prisma/prisma.service';
import {
  Body,
  Controller,
  Post,
  Req,
  UploadedFile,
  UseGuards,
  UseInterceptors,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { FileInterceptor } from '@nestjs/platform-express';
import { BugBody } from './dto/bugBody.dto';
@Controller('upload')
export class UploadController {
  constructor(private readonly prisma: PrismaService) {}
  @Post('image')
  @Auth()
  @UseInterceptors(FileInterceptor('file'))
  async image(@UploadedFile() file, @Req() req) {
    await this.prisma.user.update({
      where: {
        id: req.user.id,
      },
      data: {
        heade: file.path,
      },
    });
    return file;
  }
  @Post('bug')
  async bugSubmit(@Body() bugBody: BugBody) {
    bugBody.bugImage = JSON.stringify(bugBody.bugImage);
    const result = await this.prisma.bug.create({
      data: bugBody,
    });
    return result;
  }
}
